using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Configuration;
using System.Collections.Specialized;
using System.Web.Caching;

namespace BCGC.BLL.Helper
{
    public class CustomSiteMap
    {
        #region Direct Link Access Properties

        /* *******************************************
         * There needs to be a property for each page,
         * it is strongly recommanded to navigate pages
         * this way and there should not be any hard
         * coded url in the whole application.
         * *******************************************/

        public static string Home
        {
            get { return GetUrl(PageTitle.Home); }
        }

        public static string AdminUser
        {
            get { return GetUrl(PageTitle.Users); }
        }

        public static string AdminHome
        {
            get { return GetUrl(PageTitle.Admin_Home); }
        }

        public static string AdminPoll
        {
            get { return GetUrl(PageTitle.Polls); }
        }

        public static string MarketplacePosts
        {
            get { return GetUrl(PageTitle.Marketplace_Posts); }
        }

        public static string AdminLogin
        {
            get { return GetUrl(PageTitle.Admin_Login); }
        }

        public static string MemberHome
        {
            get { return GetUrl(PageTitle.Member_Home); }
        }
        public static string MarketPlaceDetails
        {
            get { return GetUrl(PageTitle.Edit_MarketPlace_Details); }
        }
        public static string AddMarketPlaceDetails
        {
            get { return GetUrl(PageTitle.Add_MarketPlace_Details); }
        }
        public static string Register
        {
            get { return GetUrl(PageTitle.Register); }
        }

        public static string Login
        {
            get { return GetUrl(PageTitle.Login); }
        }

        public static string RegistrationConfirmation
        {
            get { return GetUrl(PageTitle.Registration_Confirmation); }
        }

        public static string RegistrationComplete
        {
            get { return GetUrl(PageTitle.Registration_Complete); }
        }

        public static string VerifyRegistration
        {
            get { return GetUrl(PageTitle.Verify_Registration); }
        }

        public static string ForgotPassword
        {
            get { return GetUrl(PageTitle.Forgot_Password); }
        }

        public static string EmailTemplates
        {
            get { return GetUrl(PageTitle.Email_Templates); }
        }

        public static string AddEmailTemplate
        {
            get { return GetUrl(PageTitle.Add_Email_Template); }
        }

        public static string EditEmailTemplate
        {
            get { return GetUrl(PageTitle.Edit_Email_Template); }
        }

        public static string SiteSettings
        {
            get { return GetUrl(PageTitle.Site_Settings); }
        }

        public static string PrivateMessage
        {
            get { return GetUrl(PageTitle.Private_Message); }
        }

        public static string AddPrivateMessage
        {
            get { return GetUrl(PageTitle.Add_PrivateMessage); }
        }

        public static string EditPrivateMessage
        {
            get { return GetUrl(PageTitle.Edit_PrivateMessage); }
        }

        public static string Forum
        {
            get { return GetUrl(PageTitle.Forum); }
        }

        public static string PostCategory
        {
            get { return GetUrl(PageTitle.PostCategory); }
        }

        public static string AddPostCategory
        {
            get { return GetUrl(PageTitle.Add_PostCategory); }
        }

        public static string EditPostCategory
        {
            get { return GetUrl(PageTitle.Edit_PostCategory); }
        }

        public static string UserDetail
        {
            get { return GetUrl(PageTitle.User_Detail); }
        }

        public static string Users
        {
            get { return GetUrl(PageTitle.Users); }
        }

        public static string MemberProfile
        {
            get { return GetUrl(PageTitle.Member_Profile); }
        }

        public static string RecoverPassword
        {
            get { return GetUrl(PageTitle.Recover_Password); }
        }

        public static string Announcements
        {
            get { return GetUrl(PageTitle.Announcements); }
        }

        public static string AddAnnouncement
        {
            get { return GetUrl(PageTitle.Add_Announcement); }
        }

        public static string PostTag
        {
            get { return GetUrl(PageTitle.PostTag); }
        }

        public static string EditAnnouncement
        {
            get { return GetUrl(PageTitle.Edit_Announcement); }
        }

        public static string Announcement
        {
            get { return GetUrl(PageTitle.Announcement); }
        }

        public static string AddPost
        {
            get { return GetUrl(PageTitle.Add_Post); }
        }

        public static string NewsList
        {
            get { return GetUrl(PageTitle.News_List); }
        }

        public static string AddNews
        {
            get { return GetUrl(PageTitle.Add_News); }
        }

        public static string EditNews
        {
            get { return GetUrl(PageTitle.Edit_News); }
        }

        public static string News
        {
            get { return GetUrl(PageTitle.News); }
        }

        public static string NewsDetail
        {
            get { return GetUrl(PageTitle.News_Detail); }
        }

        public static string AnnouncementDetail
        {
            get { return GetUrl(PageTitle.Announcement_Detail); }
        }

        public static string Resource
        {
            get { return GetUrl(PageTitle.Resource); }
        }

        public static string CheatCodes
        {
            get { return GetUrl(PageTitle.Cheat_Codes); }
        }

        public static string AddCheatCode
        {
            get { return GetUrl(PageTitle.Add_Cheat_Code); }
        }

        public static string EditCheatCode
        {
            get { return GetUrl(PageTitle.Edit_Cheat_Code); }
        }

        public static string Wallpapers
        {
            get { return GetUrl(PageTitle.Wallpapers); }
        }

        public static string AddWallpaper
        {
            get { return GetUrl(PageTitle.Add_Wallpaper); }
        }

        public static string EditWallpaper
        {
            get { return GetUrl(PageTitle.Edit_Wallpaper); }
        }

        public static string Cracks
        {
            get { return GetUrl(PageTitle.Cracks); }
        }

        public static string AddCrack
        {
            get { return GetUrl(PageTitle.Add_Crack); }
        }

        public static string EditCrack
        {
            get { return GetUrl(PageTitle.Edit_Crack); }
        }

        public static string Trials
        {
            get { return GetUrl(PageTitle.Trials); }
        }

        public static string AddTrial
        {
            get { return GetUrl(PageTitle.Add_Trial); }
        }

        public static string EditTrial
        {
            get { return GetUrl(PageTitle.Edit_Trial); }
        }

        public static string Trailers
        {
            get { return GetUrl(PageTitle.Trailers); }
        }

        public static string AddTrailer
        {
            get { return GetUrl(PageTitle.Add_Trailer); }
        }

        public static string EditTrailer
        {
            get { return GetUrl(PageTitle.Edit_Trailer); }
        }

        public static string Patches
        {
            get { return GetUrl(PageTitle.Patches); }
        }

        public static string AddPatch
        {
            get { return GetUrl(PageTitle.Add_Patch); }
        }

        public static string EditPatch
        {
            get { return GetUrl(PageTitle.Edit_Patch); }
        }

        public static string OtherResources
        {
            get { return GetUrl(PageTitle.OtherResources); }
        }

        public static string AddOtherResource
        {
            get { return GetUrl(PageTitle.Add_OtherResource); }
        }

        public static string EditOtherResource
        {
            get { return GetUrl(PageTitle.Edit_OtherResource); }
        }

        public static string Resources
        {
            get { return GetUrl(PageTitle.Resources); }
        }

        public static string GameCheatCodes
        {
            get { return GetUrl(PageTitle.Game_Cheat_Codes); }
        }

        public static string GameCracks
        {
            get { return GetUrl(PageTitle.Game_Cracks); }
        }

        public static string GameTrials
        {
            get { return GetUrl(PageTitle.Game_Trials); }
        }

        public static string GamePatches
        {
            get { return GetUrl(PageTitle.Game_Patches); }
        }

        public static string GameTrailers
        {
            get { return GetUrl(PageTitle.Game_Trailers); }
        }

        public static string GameWallpapers
        {
            get { return GetUrl(PageTitle.Game_Wallpapers); }
        }

        public static string GameOtherResources
        {
            get { return GetUrl(PageTitle.Game_OtherResources); }
        }

        public static string DetailsPost
        {
            get { return GetUrl(PageTitle.Details_Post); }
        }

        public static string DiscussionForum
        {
            get { return GetUrl(PageTitle.Discussion_Forum); }
        }

        public static string RecentPost
        {
            get { return GetUrl(PageTitle.Recent_Post); }
        }

        public static string GameCheatCodeDetail
        {
            get { return GetUrl(PageTitle.Game_Cheat_Code_Detail); }
        }

        public static string GameCrackDetail
        {
            get { return GetUrl(PageTitle.Game_Crack_Detail); }
        }

        public static string GameTrailerDetail
        {
            get { return GetUrl(PageTitle.Game_Trailer_Detail); }
        }

        public static string GameTrialDetail
        {
            get { return GetUrl(PageTitle.Game_Trial_Detail); }
        }

        public static string GamePatchDetail
        {
            get { return GetUrl(PageTitle.Game_Patch_Detail); }
        }

        public static string GameWallpaperDetail
        {
            get { return GetUrl(PageTitle.Game_Wallpaper_Detail); }
        }

        public static string GameOtherResourcesDetail
        {
            get { return GetUrl(PageTitle.Game_Other_Resources_Detail); }
        }

        public static string StartTopic
        {
            get { return GetUrl(PageTitle.Start_Topic); }
        }
        public static string ShowTopic
        {
            get { return GetUrl(PageTitle.Show_Topic); }
        }

        public static string ReportAbuse
        {
            get { return GetUrl(PageTitle.Report_Abuse); }
        }

        public static string MarketPlace
        {
            get { return GetUrl(PageTitle.MarketPlace); }
        }

        public static string SubmitToMarket
        {
            get { return GetUrl(PageTitle.Submit_To_Market); }
        }

        public static string AddMoreSize
        {
            get { return GetUrl(PageTitle.Add_More_Size); }
        }

        public static string EditMoreSize
        {
            get { return GetUrl(PageTitle.Edit_More_Size); }
        }

        public static string ContactList
        {
            get { return GetUrl(PageTitle.Contact_List); }
        }

        public static string ReadMessage
        {
            get { return GetUrl(PageTitle.Read_Message); }
        }

        public static string CMS
        {
            get { return GetUrl(PageTitle.CMS); }
        }

        public static string ContactUs
        {
            get { return GetUrl(PageTitle.Contact_Us); }
        }
        public static string MailBox
        {
            get { return GetUrl(PageTitle.MailBox); }
        }
        public static string MailDetails
        {
            get { return GetUrl(PageTitle.MailDetails); }
        }

        public static string MailOutBox
        {
            get { return GetUrl(PageTitle.Out_Box); }
        }

        public static string ComposeMessage
        {
            get { return GetUrl(PageTitle.Compose_Message); }
        }

        public static string AddMoreDownloadFormat
        {
            get { return GetUrl(PageTitle.Add_More_Download_Format); }
        }

        public static string EditMoreDownloadFormat
        {
            get { return GetUrl(PageTitle.Edit_More_Download_Format); }
        }

        #endregion

        /// <summary>
        /// Takes a page title enumeration and returns 
        /// the url for the page that has the title in
        /// the sitemap file. PageTitle needs to be
        /// unique and there is a scope of perfomance
        /// tune for this method.
        /// </summary>
        /// <param name="pageTitle">Enumeration that represents title in the web.sitemap</param>
        /// <returns>The first url that has the title of the enumeration</returns>
        public static string GetUrl(PageTitle pageTitle)
        {
            StringDictionary urlDictornary = (StringDictionary)HttpContext.Current.Cache["SiteMap"];

            if (urlDictornary == null)
            {
                urlDictornary = new StringDictionary();
                SiteMapNodeCollection siteMapNodes = SiteMap.Provider.RootNode.GetAllNodes();

                if (siteMapNodes != null)
                {
                    urlDictornary.Add(SiteMap.Provider.RootNode.Title, SiteMap.Provider.RootNode.Url);

                    foreach (SiteMapNode node in siteMapNodes)
                    {
                        urlDictornary.Add(node.Title, node.Url);
                    }
                }
                HttpContext.Current.Cache.Insert("SiteMap",urlDictornary, null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration);
            }

            return urlDictornary[pageTitle.ToString().Replace('_',' ')];
        }

        /// <summary>
        /// Unique enumeration for the page titles in the 
        /// web.sitemap file. It is recommanded not to put
        /// same title for multiple url
        /// </summary>
        public enum PageTitle
        {
            Home = 1,
            Admin_Home,
            Polls,
            Users,
            Marketplace_Posts,
            Admin_Login,
            Member_Home,
            Register,
            Login,
            Registration_Confirmation,
            Registration_Complete,
            Verify_Registration,
            Edit_MarketPlace_Details,
            Forgot_Password,
            Email_Templates,
            Add_Email_Template,
            Edit_Email_Template,
            Site_Settings ,
            Add_MarketPlace_Details,
            Private_Message,
            Add_PrivateMessage,
            Edit_PrivateMessage,
            User_Detail,
            Forum,
            PostCategory,
            Add_PostCategory,
            Edit_PostCategory,
            Member_Profile,
            Recover_Password,
            Announcements,
            Add_Announcement,
            PostTag,
            Edit_Announcement,
            Announcement,
            Add_Post,
            News_List,
            Add_News,
            Edit_News,
            News,
            News_Detail,
            Announcement_Detail,
            Resource,
            Cheat_Codes,
            Add_Cheat_Code,
            Edit_Cheat_Code,
            Wallpapers,
            Add_Wallpaper,
            Edit_Wallpaper,
            Cracks,
            Add_Crack,
            Edit_Crack,
            Trials,
            Add_Trial,
            Edit_Trial,
            Trailers,
            Add_Trailer,
            Edit_Trailer,
            Patches,
            Add_Patch,
            Edit_Patch,
            OtherResources,
            Add_OtherResource,
            Edit_OtherResource,
            Resources,
            Game_Cheat_Codes,
            Game_Cracks,
            Game_Trials,
            Game_Patches,
            Game_Trailers,
            Game_Wallpapers,
            Game_OtherResources,
            Details_Post,
            Discussion_Forum,
            Recent_Post,
            Game_Cheat_Code_Detail,
            Game_Crack_Detail,
            Game_Trailer_Detail,
            Game_Trial_Detail,
            Game_Patch_Detail,
            Game_Wallpaper_Detail,
            Game_Other_Resources_Detail,
            Start_Topic,
            Show_Topic,
            Report_Abuse,
            MarketPlace,
            Submit_To_Market,
            Add_More_Size,
            Edit_More_Size,
            Contact_List,
            Read_Message,
            CMS,
            Contact_Us,
            MailBox,
            Add_More_Download_Format,
            Edit_More_Download_Format,
            MailDetails,
            Out_Box,
            Compose_Message
        }
    }
}
